Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix spot export error for multiple grains #429

Merged
merged 1 commit into from
Apr 18, 2022

Conversation

psavery
Copy link
Collaborator

@psavery psavery commented Apr 18, 2022

When multiple grains were being exported simultaneously due to
multiprocessing the pull_spots() function, a race condition would
cause an error with this body of code:

if not os.path.exists(output_dir):
    os.makedirs(output_dir)

Basically, two processes would both see at the same time that the
output directory does not exist, and then they would both try to
make it at the same time. One process would make the directory,
however, and then the second process would get a FileExistsError
because the directory was already created.

To avoid the race condition, just modify the code to this:

os.makedirs(output_dir, exist_ok=True)

This appears to fix the issue in my testing.

Fixes: HEXRD/hexrdgui#1192

When multiple grains were being exported simultaneously due to
multiprocessing the `pull_spots()` function, a race condition would
cause an error with this body of code:

```python
if not os.path.exists(output_dir):
    os.makedirs(output_dir)
```

Basically, two processes would both see at the same time that the
output directory does not exist, and then they would both try to
make it at the same time. One process would make the directory,
however, and then the second process would get a `FileExistsError`
because the directory was already created.

To avoid the race condition, just modify the code to this:

```python
os.makedirs(output_dir, exist_ok=True)
```

This appears to fix the issue in my testing.

Signed-off-by: Patrick Avery <patrick.avery@kitware.com>
@psavery psavery merged commit 93fb8ae into HEXRD:master Apr 18, 2022
@psavery psavery deleted the fix-spot-export-error branch April 18, 2022 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Spot exporting error in HEDM --> Fit Grains for multi-detector instruments.
2 participants